package com.javabasic.algorithm.leetcode;

public class ReverseInteger {
    private int result = 0;


    public int reverse(int x) {


        while (x != 0) {
            int cur = x%10;
            x /= 10;
            if (result > Integer.MAX_VALUE / 10 || (result == Integer.MAX_VALUE / 10 && cur > 7))
                return 0;
            if (result < Integer.MIN_VALUE / 10 || (result == Integer.MIN_VALUE / 10 && cur < -8))
                return 0;
            result = result*10 + cur;
        }

        return result;
    }
}
